package com.kimho.truck.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kimho.core.PageInfo;
import com.kimho.truck.domain.Truck;
import com.kimho.truck.persistence.TruckMapper;
import com.kimho.util.Util;

@Service
public class TruckService {
	@Autowired
	private TruckMapper truckMapper;
	/**
	 * 获取主键id
	 * @return
	 */
	
	public Long getTotal() {
		return truckMapper.getTotal();
	}
	
	/**
	 * 获取某个用户
	 * @param param
	 * @return
	 */
	@Transactional
	public Truck getTruck(Map<String,Object> param) {
		return truckMapper.getTruck(param);
	}
	/**
	 * 获取用户列表
	 * @return
	 */
	@Transactional
	public List<Truck> getTruckList(PageInfo pi) {
		return truckMapper.getTruckList(pi);
	}
	/**
	 * 新增用户
	 * @param user
	 * @param param
	 */
	@Transactional(rollbackFor=Exception.class)
	public void insertTurck(Truck truck) {

			truckMapper.insertTruck(truck);

	}
	/**
	 * 编辑用户
	 * @param user
	 * @param param
	 */
	@Transactional
	public void updateTruck(Truck truck,Map<String,Object> param) {
		//编辑用户
		truckMapper.updateTruck(truck);
		//删除原有的用户角色关联
		truckMapper.deleteTruckowner(param);
		//新增用户角色关联
		truckMapper.insertTruckowner(truck);
	}
	/**
	 * 删除用户
	 * @param param
	 */
	@Transactional
	public void deletTuck(Map<String,Object> param) {
		String ids = (String)param.get("ids");
		String[] idsArray = ids.split(",");
		for(int i=0;i<idsArray.length;i++) {
			param.put("id", idsArray[i]);
			truckMapper.deleteTruck(param);
			truckMapper.deleteTruckowner(param);
		}
	}


}
